const std = @import("std");

pub fn build(b: *std.Build) void {
    // 1. 设置目标平台与构建模式（默认 any-target / Debug）
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const module = b.createModule(.{
        .target = target,
        .optimize = optimize,
        .root_source_file = .{
            .src_path = .{
                .owner = b,
                .sub_path = "src/main.zig",
            },
        },
    });

    // 2. 声明一个可执行文件
    const exe = b.addExecutable(.{
        .name = "demo", // 生成的可执行文件名
        .root_module = module,
    });

    // 3. 把它注册为默认安装步骤
    b.installArtifact(exe);

    // 4. 注册一个运行步骤： zig build run
    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());
    // 允许通过命令行把额外参数传给程序： zig build run -- arg1 arg2
    if (b.args) |args| run_cmd.addArgs(args);

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    // 5. 注册测试步骤： zig build test
    if (false) {
        const test_step = b.step("test", "Run unit tests");
        const tests = b.addTest(.{
            .root_module = module,
        });
        test_step.dependOn(&tests.step);
    }
}
